package view;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.WindowConstants;

import controller.ControladorVistas;



/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class Login extends javax.swing.JFrame {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JLabel jLabel1;
	private JComboBox jComboBoxOficinas;
	private JButton jButtonIngresar;
	private ControladorVistas cont;
	private int nroOficina;

	public Login() {
		super("Login");
		this.setVisible(true);
		initGUI();
	}

	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			getContentPane().setLayout(null);
			getContentPane().setBackground(new java.awt.Color(64,128,128));
			{
				jLabel1 = new JLabel();
				getContentPane().add(jLabel1);
				jLabel1.setText("Seleccione el sitio de acceso:");
				jLabel1.setBounds(34, 18, 186, 14);
				jLabel1.setBackground(new java.awt.Color(193,253,153));
				jLabel1.setOpaque(true);
			}
			{

				jComboBoxOficinas = new JComboBox();
				getContentPane().add(jComboBoxOficinas);
				jComboBoxOficinas.setBounds(34, 57, 214, 26);
				jComboBoxOficinas.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						nroOficina = jComboBoxOficinas.getSelectedIndex();
						jButtonIngresar.setEnabled(true);

					}
				});
			}
			{
				jButtonIngresar = new JButton();
				getContentPane().add(jButtonIngresar);
				jButtonIngresar.setText("Ingresar");
				jButtonIngresar.setEnabled(false);
				jButtonIngresar.setBounds(285, 57, 119, 26);
				jButtonIngresar.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						if (nroOficina != 0)
							cont.procesarIngreso(nroOficina);
					}
				});
			}
			pack();
			this.setSize(512, 260);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void actualizarListaOficinas(String[] lista) {

		ComboBoxModel jComboModel = new DefaultComboBoxModel(lista);
		jComboBoxOficinas.setModel(jComboModel);

	}

	public void setControlador(ControladorVistas c) {
		this.cont = c;

	}

}
